<template>
	<view>

		<view class="good-list">
			<view class="box-left">
				<radio :checked="item.goods_state" color="#da0000" v-if="showRadio" @click="radioClickHandler"></radio>
				<image :src="item.goods_small_logo" style="width: 100px;height: 100px;" mode="widthFix"></image>
			</view>

			<view class="box-right">
				<text>{{item.goods_name}}</text>
				<view class="goods-info-box">
					<text style="color: red; font-size: 20px;">￥{{item.goods_price}}</text>
					<uni-number-box :min="1" :value="item.goods_count" v-if="showNum"
						@change="numChangeHandler"></uni-number-box>
				</view>
			</view>

		</view>



	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			item: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {

			}

		},
		methods: {
			radioClickHandler() {
				// 通过this.$emit 触发外界通过@绑定的radio-change事件
				this.$emit('radio-change', {
					goods_id: this.item.goods_id,
					goods_state: !this.item.goods_state
				})
			},
			numChangeHandler(newVal) {
				this.$emit('num-change', {
					goods_id: this.item.goods_id,
					goods_count: +newVal
				})
			}
		}


	}
</script>

<style lang="scss">
	.good-list {
		display: flex;
		border-bottom: 1px solid #efefef;

		margin-top: 5px;
	}

	.box-left {

		display: flex;
		margin-right: 5px;
		align-items: center;
		justify-content: space-between
	}

	.box-right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.goods-info-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
</style>